package com.yuandian.management.controller;

import com.yuandian.api.management.entity.ConfComponentInfoConfig;
import com.yuandian.api.management.entity.ConfGraph;
import com.yuandian.api.management.entity.ConfNetTopology;
import com.yuandian.api.management.entity.ConfNodeProperty;
import com.yuandian.api.management.validate.DeleteFlag;
import com.yuandian.api.management.validate.InsertFlag;
import com.yuandian.api.management.validate.UpdateFlag;
import com.yuandian.api.management.vo.ConfNetTopologyVo;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.management.service.ConfComponentInfoConfigService;
import com.yuandian.management.service.NetTopologyConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.groups.Default;
import java.util.List;
import java.util.Map;

/**
 * 说明：通用接口配置Controller
 * @Author zfsn
 * @Date 2023/2/21 9:38
 */
@RestController
@RequestMapping("/netTopology")
@Api(tags = "业务系统配置-网络拓扑图")
public class NetTopologyConfigController {

	@Autowired
	private NetTopologyConfigService netTopologyConfigService;

	@Autowired
	private ConfComponentInfoConfigService confComponentInfoConfigService;

	/**
	 * 通过系统id 获取it路径图
	 * @param systemId 系统id
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "获取it路径图", notes = "获取it路径图")
	@GetMapping("/{systemId}")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", value = "系统id", paramType = "query", required = true, dataType = "Integer")
	})
	public R<List<Map<String, Object>>> queryByCode(@PathVariable("systemId") Integer systemId) {
		return R.ok(netTopologyConfigService.getRoadMap(systemId));
	}


	/**
	 * 通过 id获取组件
	 * @param
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过 id获取组件", notes = "通过 id获取组件")
	@GetMapping("/getComponent/{id}")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "id(组件Id)", paramType = "path", required = true, dataType = "Integer")
	})
	public R<ConfComponentInfoConfig> getComponentById(@PathVariable("id") Integer id) {
		return R.ok(confComponentInfoConfigService.getById(id));
	}

	/**
	 * 增加节点
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "增加节点", notes = "增加节点")
	@PostMapping("/addNode")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", 	 	value = "系统id", 	paramType = "body",	 	required = true, 	dataType = "Integer"),
			@ApiImplicitParam(name = "locationX", 	 	value = "坐标x", 	paramType = "body", 	required = true, 	dataType = "Double"),
			@ApiImplicitParam(name = "locationY",	 	value = "坐标y", 	paramType = "body", 	required = true, 	dataType = "Double"),
			@ApiImplicitParam(name = "componentName", 	value = "组件名称",  paramType = "body",		required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "connectType", 	value = "连接类型",  paramType = "body",		required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "deviceType", 		value = "设备类型",  paramType = "body", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "netType", 		value = "网络类型",  paramType = "body", 	required = true, dataType = "String"),

	})
	public R<String> addNode(@RequestBody @Validated(InsertFlag.class) @ApiIgnore ConfNetTopologyVo itRoadVo) {
		return netTopologyConfigService.addNode(itRoadVo);
	}



	/**
	 * 修改节点
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "修改节点", notes = "修改节点")
	@PostMapping("/updateNode")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", 	 	value = "系统id", 	paramType = "body",	 	required = true, 	dataType = "Integer"),
			@ApiImplicitParam(name = "id", 	 	value = "组件id", 	paramType = "body",	 	required = true, 	dataType = "Integer"),
			@ApiImplicitParam(name = "componentName", 	value = "组件名称",  paramType = "body",		required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "connectType", 	value = "连接类型",  paramType = "body",		required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "deviceType", 		value = "设备类型",  paramType = "body", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "netType", 		value = "网络类型",  paramType = "body", 	required = true, dataType = "String"),

	})
	public R<String> updateNode(@RequestBody @ApiIgnore ConfNetTopologyVo itRoadVo) {
		return netTopologyConfigService.updateNode(itRoadVo);
	}

	/**
	 * 增加节点连线
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "增加节点连线", notes = "增加节点连线")
	@PostMapping("/addLink")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", 	 value = "系统id", 				 paramType = "body", 	required = true, 	dataType = "Integer"),
			@ApiImplicitParam(name = "nodeId", 		 value = "节点id, 与id对应",    paramType = "body", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "parentNodeId", value = "父节点id, 与id对应",  paramType = "body", 	required = true, 	dataType = "String"),
	})
	public R<String> addLink(@Validated({InsertFlag.class, Default.class}) @RequestBody @ApiIgnore ConfGraph confGraph) {
		return netTopologyConfigService.addLink(confGraph);
	}


	/**
	 * 删除节点连线
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "删除节点连线", notes = "删除节点连线")
	@PostMapping("/removeLink")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", 	 value = "系统id", 				 paramType = "body", 	required = true, 	dataType = "Integer"),
			@ApiImplicitParam(name = "nodeId", 		 value = "节点id, 与id对应",    paramType = "body", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "parentNodeId", value = "父节点id, 与id对应",  paramType = "body", 	required = true, 	dataType = "String"),
	})
	public R<String> removeLink(@Validated({InsertFlag.class, Default.class}) @RequestBody @ApiIgnore ConfGraph confGraph) {
		return netTopologyConfigService.removeLink(confGraph);
	}

	/**
	 * 删除节点
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "删除节点", notes = "删除节点")
	@PostMapping("/removeNode")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", value = "系统id", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "id", value = "节点id", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "isRecursiveDelete", value = "是否递归删除，默认false", paramType = "body", required = true, dataTypeClass = boolean.class)
	})
	public R<String> removeNode(@Validated({DeleteFlag.class, Default.class}) @RequestBody @ApiIgnore ConfNetTopology confSegment) {
		return netTopologyConfigService.removeNode(confSegment);
	}

	/**
	 * 移动节点
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "移动节点", notes = "移动节点")
	@PostMapping("/setLocation")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", value = "系统id", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "nodeId", value = "节点id", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "locationX", value = "坐标x", paramType = "body", required = true, dataType = "Double"),
			@ApiImplicitParam(name = "locationY", value = "坐标y", paramType = "body", required = true, dataType = "Double"),
	})
	public R<String> setLocation(@Validated({UpdateFlag.class}) @RequestBody @ApiIgnore ConfNodeProperty confNodeProperty) {
		return netTopologyConfigService.setLocation(confNodeProperty);
	}
}
